package com.zl.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author ljm
 * @Date 2021/11/25 9:18
 */
public class TestInterceptor3 implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        // 请求到达服务器之前执行，
        System.out.println("拦截器3方法前preHandle....");;
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        //控制器方法执行完成并且在给用户产生响应之前,我们可以在拦截器中通过mv控制给用户产生的响应数据
        System.out.println("请求到达拦截器3的postHandle...");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        //控制方法执行完成以后执行的方法,一般用来做资源关闭
        System.out.println("拦截器3的afterCompletion....");
    }
}
